/**
 *@filename		func.js
 *@function		Common JS Lib
 *@author		zfkun <zfkun@163.com>
 *@copyright	ku6.com
 *@datetime		2007-01-14
 *@lasttime		2007-06-04
 */
Common = {
	url: {
		domain  : 'ku6.com',
		www		: 'http://www.ku6.com/',
		img		: 'http://img.ku6.com/',
		img1	: 'http://image.ku6.com/',
		img2	: 'http://image.ku6.com/',
		js		: 'http://js.ku6.com/',
		blog	: 'http://blog.ku6.com/',
		my		: 'http://my.ku6.com/',
		so		: 'http://so.ku6.com/',
		passport: 'http://passport.ku6.com/',
		tmp		: 'http://tmp.ku6.com/',
		uga		: 'http://uga.ku6.com/',
		money	: 'http://888.ku6.com/',
		money2	: 'http://8882.ku6.com/',
		bbs		: 'http://bbs.ku6.com/',
		stat    : "http://stat.ku6.com/",
		comment : 'http://comment.ku6.com/',
		podcast : 'http://v.ku6.com/'
	},
	blogtype:{blog:0, video:1, song:2, photo:3, article:4, fav:5, friendlink:6, style:7, special:8, album:9 },
	anyOneComment: true,
	anyOneGrade: true,
	delayComment: true,
	LOGIN_BUG: null,
	is_opera: Prototype.Browser.Opera,
	is_ie: Prototype.Browser.IE,
	is_ff: Prototype.Browser.Gecko,
	noFlashPlug: function(id){
		var msg = '你还没有安装播放器或是没有开启Active X,'
				+ '<a href="'+ Common.url.www+'help/getplayer.html" target="_blank" class="a_red">如何开启?</a>'
				+ ' [<a href="'+ Common.url.www+'help/getplayer.html" target="_blank" class="a_red">安装播放器</a>]'
		$(id).innerHTML = msg;
	},
	getUserHead: function(uid){
		return Common.url.img2 + 'face/'+ (parseInt(uid) % 32) + '/'+ (parseInt(uid) % 257) + '/'+ uid + '/face_photo.jpg';
	},
	isLogin: function(){
		var c = '';
		for (var v in Common.cookie.names){
			eval('c = Common.cookie.names.'+v+';');
			var vv = Common.cookie.get(c);
			if (typeof(vv) != 'string' || isNaN(vv) || vv == '' ) {
				return false;
			}else{
				if(v == 'id' && parseInt(vv) < 10000){
					return false;
				}else if(v == 'name' && !Common.detect.limitLen(vv, 4, 16)){
					return false;
				}else if(v == 'sex' && parseInt(vv) < 4){
					return false;
				}else{
					return true;
				}
			}
		}
		return true;
	},
	//防止MYSQL阻塞引起登录回调停滞
	preventSlow: function(){
		Common.LOGIN_BUG = window.setInterval('Common.refreshTopMenu()',1000);
	},
	//停止 MYSQL防阻塞程序
	stopPrevent: function(flg){
		window.clearInterval(Common.LOGIN_BUG);
		typeof(_selOfLoginWindow) == 'object' && flg ? _selOfLoginWindow.close() : '';
	},
	refreshTopMenu: function(){
		
		var n = Common.cookie.names;
		var htmls = '';
		if (Common.isLogin()) {
			Common.LOGIN_BUG ? Common.stopPrevent(true) : '';
			var ppc=Common.cookie.get('systemPPCLoginUser');
			if(ppc){
				ppc = ppc.split('_--_');
			}
			var u_uid=ppc[0];
			var u_url=ppc[1];
			var u_index=(u_url&&u_url!='')?u_url:'u/'+u_uid;
			htmls += '欢迎您！<span class="danlv strong">'+ Common.cookie.get(n.name) +'</span>'
				   + ' <span id="userNewMsg"></span>'
				   + ' <a href="'+ Common.url.podcast + u_index + '" class="a_hui" target="_blank">播客</a>'
				   + ' <a href="'+ Common.url.blog + u_uid +'/" class="a_hui" target="_blank">博客</a>'
				   + ' <a href="'+ Common.url.my +'" class="a_hui" target="_blank">管理</a>'
				   + ' <a href="javascript:VLogin.logout();" class="a_hui">退出</a>'
			var u = arguments[0] ? arguments[0] : Common.url.www;
			new CheckNewMsg(u);
		} else {
			var jump = "";
			try{
				jump = '?jumpUrl='+encodeURICompent(window.location.href);
			}catch(e){}
			htmls += ' <a href="javascript:;" onclick="VLogin.show();">登录</a> '
				   + ' <a href="' + Common.url.passport + '/register.html"'+jump+' target="_blank">快速注册</a>';
		}
		$('top_userPanel').innerHTML = htmls;
	},
	move: function(consult, target){
		var patchLeft = arguments[2] ? parseInt(arguments[2]) : 0;
		var patchTop = arguments[3] ? parseInt(arguments[3]) : 0;
		var p = Position.cumulativeOffset(consult);
		var l = (p[0] + parseInt(patchLeft));
		var t = (p[1] + parseInt(patchTop));
		Element.setStyle(target,{'left':l,'top':t});
	},
	copyCode: function(inputId){
		var _o = $(inputId);
		_o.select();
		if(Common.is_ie) {
			clipboardData.setData('Text',_o.value);
		} else {
			prompt("请复制网站地址:",_o.value);
		}
	},
	copyStr: function(str){
		if(Common.is_ie) {
			clipboardData.setData('Text',str);
			alert ("“"+str+"”\n已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方");
		} else {
			prompt("请复制网站地址:",str);
		}
	},
	copyShareLink: function(str,type){
		if(Common.is_ie){
			clipboardData.setData('Text',str);
			if(type=='baidu'){
				confirm('代码已经复制到您的剪贴板中,是否继续查看使用演示教程?\r\n点"确定"查看教程,点"取消"不查看进程') ? window.open('http://www.baidu.com/search/post_img.html#n1','分享代码使用教程') : '';
			}else{
				confirm('代码已经复制到您的剪贴板中,是否继续查看使用演示教程?\r\n点"确定"查看教程,点"取消"不查看进程') ? window.open(Common.url.www+'help/teach_share.html#'+type,'分享代码使用教程') : '';
			}
		}else{
			if(type=='baidu'){
				prompt("请复制以下代码:",str) ? window.open('http://www.baidu.com/search/post_img.html#n1','分享代码使用教程') : '';
			}else{
				prompt("请复制以下代码:",str) ? window.open(Common.url.www+'help/teach_share.html#'+type,'分享代码使用教程') : '';
			}
		}
	},
	setErrorPic: function(obj, type){
		obj.onerror='';
		switch (type) {
		case "mv":
			obj.src = Common.url.img + "common/default_mv.gif";
			break;
		case "photo":
			obj.src = Common.url.img + "common/default_photo.gif";
			break;
		case "man":
			obj.src = Common.url.img + "common/default_man.gif";
			break;
		case "sort":
			obj.src = Common.url.img + "common/default_mv.gif";
			break;
		case "head":
			obj.src = Common.url.img + "common/default_head.gif";
			break;
		case "face":
			obj.src = Common.url.img + "common/default_man.gif";
			break;
		case "blank":
			obj.src = Common.url.img + "common/blank.gif";
			break;
		}

	},
	setStartPage: function(ev){
		try{
			ev.style.behavior='url(#default#homepage)';
			ev.setHomePage(Common.url.www);
		}catch(e){
			alert('对不起,Firefox下不支持此功能,请手动设置为首页!');
		}
	},
	addFavor: function(){
			var _url = arguments[0] ? arguments[0] : Common.url.www;
			var _name= arguments[1] ? arguments[1] : '酷6网';
			if(Common.is_ie) {
				window.external.addFavorite(_url,_name);
			} else if (Common.is_opera) {
				alert ("请使用Ctrl+T将本页加入收藏夹");
			} else {
				alert ("请使用Ctrl+D将本页加入收藏夹");
			}
	},
	removeUBB: function(){
	},
	openItem: function(id){
		try {
			$(id).toggle();
		} catch (e)	{}
	},
	stopBubble: function(ev,callFunc){
		try{
			ev.cancelBubble = true;
		}catch (ex){
			ev.stopPropagation();
		}{typeof(callFunc) != 'undefined' ? callFunc() : '';}
	},
	switchTab: function (did,sid){
		arguments[2] ? eval(arguments[2]+"();") : '';
		var os = $(did).getElementsByTagName("li");
		var c = os.length;
		var i = 0;
		while(i < c){
			os[i].className = '';
			i++;
		}
		$(sid).className = "sel";
	},
	toolTip: {
		sPop: null,
		popStyle: null,
		showPopupText: function(event) {
			if(event.srcElement) o = event.srcElement; else o = event.target;
			if(!o) {
				return;
			}
			MouseX = event.clientX;
			MouseY = event.clientY;
			if(o.alt != null && o.alt != '') {
				o.pop = o.alt;
				o.alt = '';
			}
			if(o.title != null && o.title != '') {
				o.pop = o.title;
				o.title = '';
			}
			var c = Common.toolTip;
			if(o.pop != c.sPop) {
				c.sPop = o.pop;
				if(c.sPop == null || c.sPop == '') {
					$('popLayer').style.visibility = "hidden";
				} else {
					c.popStyle = o.dyclass != null ? o.dyclass : 'cPopText';
					$('popLayer').style.visibility = "visible";
					c.showIt();
				}
			}
		},
		showIt: function() {
			var _o = $('popLayer');
			_o.className = Common.toolTip.popStyle;
			_o.innerHTML = Common.toolTip.sPop.replace(/<(.*)>/g,"&lt;$1&gt;").replace(/\n/g,"<br>");
			var popWidth = _o.clientWidth;
			var popHeight = _o.clientHeight;
			var popLeftAdjust = MouseX + 12 + popWidth > document.body.clientWidth ? -popWidth - 24 : 0;
			var popTopAdjust = MouseY + 12 + popHeight > document.body.clientHeight ? -popHeight - 24 : 0;
	
			_o.style.left = (MouseX + 12 + document.body.scrollLeft + popLeftAdjust) + 'px';
			_o.style.top = (MouseY + 12 + document.body.scrollTop + popTopAdjust) + 'px';
		}
	},
	dom: {
		getNodeValue: function(node, path){
			if (Common.is_ie) {
				return node.selectSingleNode(path).text;
			} else {
				return node.getElementsByTagName(path)[0].textContent;
			}
		},
		getNodes: function(node,path){
			//if (Common.is_ie) {
				//return node.selectNodes(path);
			//} else {
				return node.getElementsByTagName(path);
			//}
		}
	},
	cookie: {
		path  : '/',
		domain: 'ku6.com',
		names: {
			id	  : 'sysUserId',
			name  : 'sysUserName',
			sex	  : 'sysUserSex',
			save  : 'sysUserSavelogin',
			secure: 'sysUserSecure',
			state : 'sysUserState'
		},
		get: function(n){
			var oc = document.cookie;
			var v = "";
			var s = n + "=";
			var os= -1;
			var end;
			if (oc.length > 0) {
				os = oc.indexOf(s);
				if (os != -1) {
					os += s.length;
					end = oc.indexOf(";", os);
					
					if (end == -1){
						end = oc.length;
					}
					v = unescape(decodeURI(oc.substring(os,end)));
				}
			}
			return (v===''||v===null)?null:v;
		},
		set: function(n,value,seconds){
			var argv = arguments;
			var argc = arguments.length;
			var expires = (2 < argc) ? (new Date((new Date()).getTime() + argv[2]*1000)) : null;
			var path	= (3 < argc) ? argv[3] : Common.cookie.path;
			var domain	= (4 < argc) ? argv[4] : Common.cookie.domain;
			var secure	= (5 < argc) ? argv[5] : false;
			
			var cs  = n + "=" + encodeURI(value)
					+ ((expires == null) ? "" : ("; expires=" + expires.toGMTString()))
					+ ((path == null) ? "" : ("; path=" + path))
					+ ((domain == null) ? "" : ("; domain=" + domain))
					+ ((secure == true) ? "; secure" : "");
			document.cookie = cs;
		},
		del: function(n){
			var argv = arguments;
			var argc = arguments.length;
			var exp  = new Date((new Date()).getTime() - 3600);
			var path = (argc > 1) ? argv[1] : Common.cookie.path;
			var domain = (argc > 2) ? argv[2] : Common.cookie.domain;
			var secure = (argc > 3) ? argv[3] : false;
			switch(argc){
				case 1:
					Common.cookie.set(n,'',exp);
					return true;
					break;
				case 2:
					Common.cookie.set(n,'',exp, path);
					return true;
					break;
				case 3:
					Common.cookie.set(n,'',exp, path, domain);
					return true;
					break;
			}
		}
	},
	ajax: {
		loadData: function(u,p,l,s, f,r){
			if(arguments.length < 4){
				return ;
			}
			if (r) {
				p.get._rand = Math.random();
			}
			var url = u;
			var _getPar = p.get ? $H(p.get).toQueryString() : '';
			if(_getPar != ''){
				url += '?' + _getPar;
			}
			new Ajax.Request(
				url,
				{
				  method: arguments[6]||'post',
				  parameters: p.post ? $H(p.post).toQueryString() : '',
				  onLoading: l,
				  onSuccess: s,
				  onFailure: f
				}
			);
		},
		loadElement: function(e,u,p, f,l,r){
			if(arguments.length < 3){
				return ;
			}
			if (r) {
				p._rand = Math.random();
			}
			var url = u;
			var _getPar = p.get ? $H(p.get).toQueryString() : '';
			if(_getPar != ''){
				url += '?' + _getPar;
			}
			Element.update(e, l);
			new Ajax.Updater(
				{success: e},
				url,
				{
				  method: arguments[6]||'post',
				  parameters: p.post ? $H(p.post).toQueryString() : '',
				  onFailure: f
				}
			);
		}
	},
	dispose: {
		trim: function(s){
			return s.replace(/^\s*|\s*$/g,'');
		},
		trimBlankLine: function(s){
			return s.replace(/(\n[\s|\t]*\r*\n)/g, '\n');
		},
		ltrim:function(s){
 			return s.replace(/(^\s*)/g,"");
		},
		rtrim:function(s){
 			return s.replace(/(\s*$)/g,"");
		},
		delClipBoardCN: function(){
			var str = window.clipboardData.getData("Text");
			var s = str.replace(/[^\x00-\xff]/g,'');
			window.clipboardData.setData("Text",s);
		},
		disableCN: function(){
			var o;
			for (var i = 0; i < arguments.length; i++) {
				o = arguments[i];
				if (typeof(o) == 'string'){ o = $(o); }
				Element.setStyle(o,{imeMode:"disabled"});
				Event.observe( o, "beforepaste", Common.dispose.delClipBoardCN, false );
			}
		},
		transHTML: function(s){
			//s = s.replace(/&/g,"&amp;");
			s = s.replace(/</g,"&#60;");
			s = s.replace(/>/g,"&#62;");
			//s = s.replace(/ /g,"&nbsp;");
			s = s.replace(/\n/g,"<br/>");
			return s;
		},
		htmlDecode: function(s){
			if(s == null){return s;}
			return s.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");
		},
		HtmlEncode: function(s){
			if(s == null){return s;}
			return s.replace(/</g,"&lt;").replace(/>/g,"&gt;");
			//	return s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
		},
		replaceAll: function(Str, Src, NewStr){
			if(!Str || Str.length == 0) return "";
			return Str.split(Src).join(NewStr);
			var Buf = Str;
			if (Src.length == 0) return Buf;
			var Idx = Buf.indexOf(Src);
			while (Idx >= 0){
				Buf = Buf.substring(0, Idx) + NewStr + Buf.substr(Idx + Src.length);
				Idx = Buf.indexOf(Src, Idx + NewStr.length);
			}
			return Buf;
		},
		getLength: function(str){
			var templen = str.length;
			//if(navigator.appName == 'Netscape'){return templen;}
			for (var i = 0; i < str.length; i++) {
				var rstr = escape(str.substring(i,i+1));
				if (rstr.substring(0,2) == "%u"){ templen++; }
			}
			return templen;
		},
		sub_str: function(str,len,place){
			if(str.replace(/[^\x00-\xff]/gi,'xx').length <= len) return str;
			if(place=='left'){
				var temp_len=len;
				str=str.substr(0,len);
				while(str.replace(/[^\x00-\xff]/gi,'xx').length > len){
					str=str.substr(0,--temp_len);
				}
			}
			if(place=='right'){
				var temp_startn=0;
				str=str.substr(str.length-len,len);
				while(str.replace(/[^\x00-\xff]/gi,'xx').length>len){
					str=str.substr(1,len);
				}
			}
			return str;
		},
		formatTime: function(sec){
			var len = arguments[1] ? parseInt(arguments[1]) : 2;
			var pad_str = arguments[2] ? arguments[2] : '0';
			var align = arguments[3] ? parseInt(arguments[3]) : 0;
			var type = arguments[4] ? parseInt(arguments[4]) : 0
			var t = parseInt(sec);
			var h = 0;
			var m = 0;
			var s = 0;

			h = Math.floor(t / 3600);
			m = Math.floor((t - h * 3600) / 60);
			s = t - h * 3600 - m * 60;
			
			switch(type){
				case 0:
					return h.toString().pad(len,pad_str,type)+':'+m.toString().pad(len,pad_str,type)+':'+s.toString().pad(len,pad_str,type);
					break;
			}
		}
	},
	detect: {
		isEmpty: function(s){
			return Common.dispose.trim(s).length == 0;
		},
		isNumber: function(s){
			return !isNaN(s);
		},
		isDouble: function(s){
			return (/^[-\+]?\d+(\.\d+)?$/).test(Common.dispose.trim(s));
		},
		isInteger: function(s){
			return (/^[-\+]?\d+$/).test(Common.dispose.trim(s));
		},
		isEnglish: function(s){
			return (/^[A-Za-z]+$/).test(Common.dispose.trim(s));
		},
		isChinese: function(s){
			return (/^[\u0391-\uFFE5]+$/).test(Common.dispose.trim(s));
		},
		isDoubleChar: function(s){
			return (/^[^\x00-\xff]+$/).test(Common.dispose.trim(s));
		},
		isDate: function(s){
			return (/^\d{4}|\d{2}-\d{1,2}-\d{1,2}$/).test(Common.dispose.trim(s));
		},
		isQQ: function(s){
			return (/^[1-9]\d{4,11}$/).test(Common.dispose.trim(s));
		},
		isEmail: function(s){
			return (/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$/).test( Common.dispose.trim(s) );
		},
		isMobile: function(s){
			return (/^1[3|5]\d{9}$/).test(Common.dispose.trim(s));
		},
		isPhone: function(s){
			return (/^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/).test(Common.dispose.trim(s));
		},
		isZip: function(s){
			return (/^[1-9]\d{5}$/).test(Common.dispose.trim(s));
		},
		isCard: function(s){
			var aCity="11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91,";
			var iSum=0;
			var info="";
			var sId="";
			if (s.length==15){
				sId=s.substr(0,6)+"19"+s.substr(6,9)+"0";
			}else if (s.length==18){
				sId=s;
			}else{
				return false;
			}
	
			xb=Number(sId.substr(16,1))%2;
	
			if(!/^\d{17}(\d|x)$/i.test(sId)){return false;}
			sId=sId.replace(/x$/i,"a");
			if(aCity.indexOf(sId.substr(0,2))==-1){return false;}
			sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));
			var d=new Date(sBirthday.replace(/-/g,"/"));
			if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate())){
				return false;
			}
			if (s.length==18) {
				for(var i = 17;i>=0;i --){
					iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11);
				}
				if(iSum%11!=1) {return false;}
			}
			return true;
		},
		isURL: function(s){
			return (/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/).test(Common.dispose.trim(s).toLowerCase());
		},
		isTag: function(s){
			return !(/[-\~!@#\$%\^&\*\,\.\(\)\[\]\{\}<>\?\\\/\'\"\|\、\，\。\‘\’\“\”\？\￥\……\！]/i).test(s);
		},
		isColor: function(s){
			if (Common.dispose.trim(s).length != 7) return false;
			return Common.dispose.trim(s).search(/\#[a-fA-F0-9]{6}/) != -1;
		},
		isRubbish: function(s){
			return (/[\w-\~!@#\$%\^&\*\,\.\(\)\[\]\{\}<>\?\\\/\'\"\|]{65,}/i).test(s)
		},
		hasInvalidateVCodeChar: function(s){
			return (/[^a-zA-Z0-9]+$/).test(s);
		},
		hasChineseChar: function(s){
			return (/[^\x00-\xff]/).test(s);
		},
		hasAvailableChar: function(s){
			return (/^[a-zA-Z0-9_-]{0,}$/).test(s);
		},
		hasUnAvailableChar: function(s){
			return (/[^a-zA-Z0-9_-]/i).test(Common.dispose.trim(s).toLowerCase());
		},
		hasUnAvailableChar2: function(s){
			return (/[^\u0391-\uFFE5a-zA-Z0-9_-]/i).test(Common.dispose.trim(s).toLowerCase());
		},
		limitLen: function(s,Min,Max){
			s = Common.dispose.trim(s);
			var ss = Common.dispose.getLength(s);
			if( ss < Min || ss > Max ){
				return false;
			}else{
				return true;
			}
		}
	}
};

/***最新短消息***/
var CheckNewMsg = Class.create();
CheckNewMsg.prototype = {
	initialize: function(url){
		_selOfCheckNewMsg = this;
		this._num = {user: 0, sys: 0};
		this._containers = arguments[1] ? arguments[1] : ['userNewMsg'];
		this._servUrl = url + 'ajax.php';
		Common.isLogin() ? this._load() : '';
	},
	show: function(n){
		this._set(n);
		var l = this._containers.length;
		var i = 0;
		while(i < l){
			$(this._containers[i]).innerHTML = this._createHTML();
			i++;
		}
	},
	_createHTML: function(){
		var _n = this._get();
		var _num = '';
		if(parseInt(_n.user) > 0){
			var _task = "inbox";
			_num += _n.user;
			if(parseInt(_n.sys) > 0){
				_num += "+"+_n.sys+"(系统)";
			}
		}else{
			var _task = "sysinbox";
			if(parseInt(_n.sys) > 0){
				_num += _n.sys+"(系统)";
			}else{
				return '';
			}
		}
		var html = '<a href="'+Common.url.my+'?dta=com_msg|mos_msg|task_'+_task+'" target="_blank">'
				 + '<img src="'+Common.url.img+'common/newmsg.gif" style="margin-top:4px;"><span style="font-size:11px;">'+_num+"</span>"
				 + '</a>';
		return html;
	},
	_set: function(n){
		this._num.user = parseInt(n.user);
		this._num.sys = n.sys.length;
	},
	_get: function(){
		return this._num;
	},
	_load: function(){
		var op = {
			get: {
				com	 : 'message',
				task : 'newmsg'
			},
			post: {}
		};
		Common.ajax.loadData(this._servUrl,op,'',this._callFunc,'',false,'get');
	},
	_callFunc: function(x){
		eval("var d = "+x.responseText+";");
		if(typeof(d) == 'object' && (parseInt(d.user) > 0) || ((typeof(d.sys) == 'object') && (d.sys.length > 0))){
			_selOfCheckNewMsg.show(d);
		}else{
			_selOfCheckNewMsg.show({user:0,sys:[]});
		}
	}
};

/*** 登录窗口基类 ***/
var LoginWindow = Class.create();
LoginWindow.prototype = {
	initialize: function(name,url,reloadFlg){
		_selOfLoginWindow = this;
		this._selfName	= name;
		this._tip		= 'qlogin_msg';
		this._servUrl	= url + 'ajax.php';
		this.canReload	= reloadFlg ? true : false;

		this._formFields= {
			name : 'quname',
			pwd	 : 'qupass',
			save : 'qsavelogin'
		}
	},
	show: function(){
		if (Common.isLogin()) {
			alert('您已经登录过了!');
			return ;
		}
		try {
			new winForm().custom('酷6网-登录', this.loginHTML());
			$(this._formFields.name).focus();
		} catch(e) {
			alert('登录窗口创建失败,程序将自动切换至普通登录入口');
			top.location = Common.url.passport + (document.URL ? '?jumpurl='+document.URL : '');
		}
	},
	close: function(){
		new winForm().close();
	},
	login: function(){
		if (this._checkForm()) {
			this.showMsg(0, false);
			/*
			var op = {
				get: {
					com	 : 'passport',
					task : 'login'
				},
				post: {
					uname	 : $F(this._formFields.name),
					upass	 : $F(this._formFields.pwd),
					savelogin: $F(this._formFields.save)
				}
			};
			Common.ajax.loadData(this._servUrl, op,'',this._callFuncForLogin,'',true);
			*/
			var js = document.createElement('script');
			if(js){
				var pars = 'username='+encodeURIComponent($F(this._formFields.name));
				pars += '&password='+encodeURIComponent($F(this._formFields.pwd));
				if($(this._formFields.save).checked){
					pars += '&expire=1209600';
				}
				pars += '&callBackMethod='+this._selfName+'._callFuncForLogin';
				js.src = Common.url.passport+'login.uhtm?t=doLogin&'+pars;
				js.type = 'text/javascript';
				//(function(){document.head.appendChild(js)}).delay(1);
				setTimeout(function(){document.getElementsByTagName('head')[0].appendChild(js)}, 1);
			}

			Common.preventSlow();
		}
	},
	logout: function(){
		if (!Common.isLogin()) {
			alert('您还没有登录或者您的Cookie已经失效!');
			return ;
		}
		/*
		var op = {
			get: {
				com	 : 'passport',
				task : 'logout'
			}
		};
		Common.ajax.loadData(this._servUrl,	op,	'',	this._callForLogout, '', false,'get');
		*/
		var js = document.createElement('script');
		if(js){
			js.src = Common.url.passport+'login.htm?t=doLogout&redirect=0&callBackMethod='+this._selfName+'._callForLogout';
			js.type = 'text/javascript';
			setTimeout(function(){document.getElementsByTagName('head')[0].appendChild(js)}, 1);
		}
	},
	showMsg: function(i, flg){
		$(this._tip).innerHTML	 = '<span class="red">&nbsp;&nbsp;'+ this._tipMsg[i]+'</span>';
	},
	_checkForm: function(){
		var dt = Common.detect;
		var n = $F(this._formFields.name);
		var p = $F(this._formFields.pwd);
		
		if (dt.isEmpty(n)) {
			this.showMsg(1,true);
			return false;
		}
		if (dt.isEmpty(p)) {
			this.showMsg(4,true);
			return false;
		}
		if (dt.hasChineseChar(p)) {
			this.showMsg(5, true);
			return false;
		}
		return true;
	},
	_tipMsg: [
		'验证处理中,请稍等...',
		'用户名不能为空',
		'用户名不能含有中文字符(老用户除外)',
		'用户名长度4-16位(1中文占2位)',
		'密码不能为空',
		'密码不能含有中文字符',
		'密码长度4-16位',
		'用户名不存在',
		'密码错误',
		'发生未知错误,请重试!'
	],
	statusCode: {
		'201':'用户名为空', '202': '用户名格式无效', '203': '用户名已占用', '204': '用户名未占用', '205': '邮箱为空', '206': '邮箱格式无效', '207': '邮箱已占用',
		'208': '邮箱未占用', '209': '密码为空', '210': '密码格式无效', '211': '密码错误', '212': '确认密码为空', '213': '密码与确认密码不一致', '214': '旧密码为空',
		'215': '旧密码格式无效',  '216': '验证码为空', '217': '验证码无效', '218': '验证码错误', '219': '手机号为空', '220': '手机号错误', '221': '手机号无效',
		'222': '安全码为空', '223': '安全码无效', '224': '安全码错误', '225': '注册成功', '226': '注册失败', '227': '登录成功', '228': '登录失败', '229': '已经登录',
		'230': '更新成功', '231': '更新失败', '232': '密码找回成功', '233': '密码找回失败', '234': '用户不存在', '235': '用户已封号', '236': '参数错误', '237': '邮箱不存在',
		'238':'个性域名为空', '239':'个性域名无效', '240':'个性域名已占用', '241':'个性域名未占用', '243': '昵称为空', '244': '昵称格式无效', '245': '昵称已占用',
		'246': '昵称未占用', '247':'用户未登陆', '248':'安全问题为空', '249':'安全问题格式无效', '250':'答案为空', '251':'答案格式无效', '252':'安全问题问答错误',
		'253':'旧安全问题为空', '254':'旧安全问题格式无效', '255':'旧答案为空', '256':'旧答案格式无效', '257':'邮件地址错误', '258':'您还没有设置安全邮箱', '259':'安全手机号码错误',
		'260':'您还没有设置安全手机号码', '263':'简介格式无效', '264':'退出成功', '500':'系统错误'
	},
	errorCode: {
		empty	: '403',
		unExiste: '404',
		wrong	: '406',
		nullity	: '407',
		lenError: '408'
	},
	_callFuncForLogin: function(rs,cp){
		Common.stopPrevent(false);
		var _s = _selOfLoginWindow;

		if(rs && (parseInt(rs.msgInfo)==227 || parseInt(rs.msgInfo)==229)){
			_s.close();
			if (_s.canReload) {
				document.location.reload();
			} else {
				Common.refreshTopMenu();
				try {_selfOfStar.refresh();}catch(e){}
				try{_selOfIndexLoginWindow.hide();}catch(e){}
				try{_selfOfComment.checkForbid();}catch(e){}
			}
		}else{
			var msg = this.statusCode[rs.msgInfo]||'服务器忙';
			try{
				$(this._tip).innerHTML	 = '<span class="red">&nbsp;&nbsp;'+ msg+'</span>';
			}catch(e){
				alert(msg);
			}
		}
	},
	_callForLogout: function(rs,cp){
		if (_selOfLoginWindow.canReload) {
			document.location = Common.url.www;
		} else {
			Common.refreshTopMenu();
			try{ _selfOfStar.refresh();}catch(e){}
			try{_selOfIndexLoginWindow.show();}catch(e){}
			try{_selfOfComment.checkForbid();}catch(e){}
		}
	},
	loginHTML: function(){
		return	'<div id="qmod_login">'
		+ '<div class="qmod_login_title"><span id="qlogin_msg"></span></div>'
		+ '<form name="qilogin" id="qilogin" onsubmit="return false;">'
		+ '<p><span>用户名：</span><input type="text" name="quname" id="quname" class="b4" onmouseover="changeOverInput(this.id);" onmouseout="changeOutInput(this.id);" onkeydown="if(event.keyCode == \'13\'){'+this._selfName+'.login();};" /></p>'
		+ '<p><span>密&nbsp;&nbsp;码：</span><input type="password" autocomplete="off" name="qupass" class="b4" id="qupass" onmouseover="changeOverInput(this.id);" onmouseout="changeOutInput(this.id);" onkeydown="if(event.keyCode == \'13\'){'+this._selfName+'.login();};" /></p>'
		+ '<div>'
		+ '	<input type="checkbox" name="qsavelogin" id="qsavelogin" value="y" /><label for="savelogin"><span>自动登录（网吧勿用）</span></label>'
		+ '	<a href="'+Common.url.passport+'?com=register" class="a_red">快速注册</a>'
		+ '</div>'
		+ '<input type="button" name="qlogin_submit" id="qlogin_submit"  class="p_abs hand" onclick="'+this._selfName+'.login();this.blur();" />'
		+ '</form>'
		+ '<div id="ilogin_info" class="list">'
		+ '<ul>'
		+ '<li><a href="'+Common.url.passport+'?com=getpass">忘记密码?</a></li>'
		+ '</ul>'
		+ '<div class="clear"></div>'
		+ '</div>'
		+ '<div class="clear"></div>'
		+ '</div>';
	}
};

//搜索框判断
function searchBarFormCheck()
{
	if($('key').value.length<1){
		alert('关键词不能为空');
		$('key').focus();
		return false;
	}else{
		var key = $('key').value.replace(/\//g,'');
		var by = $('by').value;
		var searchUrl = $('searchBar').action + '?key=' + encodeURIComponent(key) + '&by=' + by;
		window.location.href=searchUrl;
		return false;
	}
}

//得到url的GET参数值
function getParameter(name)
{
	var reg = new RegExp("(^|&|\\?|\\s)"+ name +"\\s*=\\s*([^&]*?)(\\s|&|$)", "i");
	if (reg.test(document.location.search)) return RegExp.$2.replace(/[\x0f]/g, ";"); return "";
}

function changeOverInput(id,cn){
	$(id).className = cn+" changeOverInput";
}
function changeOutInput(id, cn){
	$(id).className = cn+" changeOutInput";
}

if(!document.onmouseover) {
	document.onmouseover = function(e) {
		var event = e ? e : window.event;
		Common.toolTip.showPopupText(event);
	};
}
String.prototype.pad = function(l, s, p){
    return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)+ 1).join(s)).substr(0, p=!p ? l : p == 1 ? 0 : Math.ceil(l / 2))+ this + s.substr(0, l-p) : this;
};
Array.prototype.in_array = function(v) {
	var l = this.length;
	for(var i=0; i<=l; i++) {
		if(this[i]==v) return true;
	}
	return false;
}

/**
 * QuickPlayList Manager
 */
_pre_='qk_';
__n__='QPL';
__s__=',';
__c__=Common.cookie.get(__n__);
if(!__c__){ QPL = new Array();}
else{ QPL = __c__.split(__s__); }

function checkQuickList(){
	if(QPL.constructor!==Array){return false;}
	var _l=QPL.length;
	for(var i=0;i<_l;i++){
		var _o = $(_pre_+QPL[i]);
		if(_o){
			_o?_o.firstChild.title="从快捷连播菜单中删除":'';
			Element.classNames(_o).add('add_sel');
		}
	}
}
function clickQuickBtn(vid){
	if(QPL.constructor!==Array){return false;}
	QPL.in_array(vid)?removeQuickList(vid):addQuickList(vid);
}
function addQuickList(vid){
	var _o = $(_pre_+vid);
	_o?_o.firstChild.title="从快捷连播菜单中删除":'';
	Element.classNames(_o).add('add_sel');
	var _c = Common.cookie.get(__n__);
	_c = !_c ? vid : (_c+__s__+vid);
	Common.cookie.set(__n__,_c);
	QPL = _c.split(__s__);
}
function removeQuickList(vid){
	var _o = $(_pre_+vid);
	_o?_o.firstChild.title="添加到快捷连播菜单":'';
	Element.classNames(_o).remove('add_sel');
	for(var v in QPL){ if(QPL[v]==vid){ var i=v; } }
	if(i){
		QPL.splice(i,1);
		Common.cookie.set(__n__,QPL.join(','));
	}
}
function clearQuickList(){
	Common.cookie.del(__n__);
	if(QPL.constructor!==Array){return false;}
	for(var v in QPL){
		var _o = $(_pre_+QPL[v]);
		_o?_o.firstChild.title="添加到快捷连播菜单":'';
		_o?Element.classNames(_o).remove('add_sel'):'';
	}
	QPL.clear();
}